package com.qfedu.yanglao20admin.sysmessage.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qfedu.yanglao20.entity.sysmessage.MsgManage;
import com.qfedu.yanglao20admin.sysmessage.dao.MsgManageDao;
import com.qfedu.yanglao20admin.sysmessage.param.MsgCenter;
import com.qfedu.yanglao20admin.sysmessage.service.MsgManageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (MsgManage)表服务实现类
 *
 * @author makejava
 * @since 2023-04-19 21:28:46
 */
@Service("msgManageService")
public class MsgManageServiceImpl implements MsgManageService {
    @Resource
    private MsgManageDao msgManageDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public MsgManage queryById(Integer id) {
        return this.msgManageDao.queryById(id);
    }


    /**
     * @param msgCenter
     * @return
     */
    @Override
    public Page<MsgManage> queryByPage(MsgCenter msgCenter) {
        Page<MsgManage> msg = new Page<>((msgCenter.getCurrent() - 1) * msgCenter.getSize(),
                msgCenter.getSize());
        msgCenter.setCurrent((msgCenter.getCurrent() - 1) * msgCenter.getSize());
        List<MsgManage> page = msgManageDao.selectPage(msgCenter);
        msg.setRecords(page);
        Long aLong = msgManageDao.selectCount(null);
        msg.setTotal(aLong);
        return msg;
    }

    /**
     * 新增数据
     *
     * @param msgManage 实例对象
     * @return 实例对象
     */
    @Override
    public MsgManage insert(MsgManage msgManage) {
        this.msgManageDao.insert(msgManage);
        return msgManage;
    }

    /**
     * 修改数据
     *
     * @param msgManage 实例对象
     * @return 实例对象
     */
    @Override
    public MsgManage update(MsgManage msgManage) {
        this.msgManageDao.update(msgManage);
        return this.queryById(msgManage.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.msgManageDao.deleteById(id) > 0;
    }
}
